/**
 * <AiRmob-Framework; A simple augmented reality framework for android >
    Copyright (C) <2012>  <AiRmob Team>

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package rendercomponents;

public class VectorMethods {

	/**
	 * Normalizes a given float[3] in-place.
	 * 
	 * @param vector3D
	 */
	static public void normalize(float[] vector3D){
		float length = (float) Math.sqrt(vector3D[0] * vector3D[0] + vector3D[1] * vector3D[1] + vector3D[2] * vector3D[2]);
		vector3D[0] = vector3D[0] / length;
		vector3D[1] = vector3D[1] / length;
		vector3D[2] = vector3D[2] / length;
	}
	
	/**
	 * Calculates the cross-product of two vectors and stores the result in another.
	 * 
	 * @param vector1
	 * @param vector2
	 * @param result
	 */
	static public void cross(float[] vector1, float[] vector2, float[] result){	
		result[0] = vector1[1] * vector2[2] - vector1[2] * vector2[1];
		result[1] = vector1[2] * vector2[0] - vector1[0] * vector2[2];
		result[2] = vector1[0] * vector2[1] - vector1[1] * vector2[0];		
	}	
	
	/**
	 * Calculates the dot-product of two vectors and stores the result in another.
	 * 
	 * @param vector1
	 * @param vector2
	 * @param result
	 */
	static public void dot(float[] vector1, float[] vector2, float result){
		result = vector1[0] * vector2[0] + vector1[1] * vector2[1] + vector1[2] * vector2[2]; 
	}
}
